#include "creategroupdialog.h"
#include "ui_creategroupdialog.h"
#include "utils.h"
#include "global_var.h"

#include <QMessageBox>

CreateGroupDialog::CreateGroupDialog(Dashboard* dashboard, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CreateGroupDialog)
{
    ui->setupUi(this);
    this->dashboard = dashboard;
}

CreateGroupDialog::~CreateGroupDialog()
{
    delete ui;
}

void CreateGroupDialog::on_buttonBox_accepted()
{
    if(is_exist(ui->input_gname->text(), groups)) {
        QMessageBox::information(this, tr("Error"), tr("组名已存在"), QMessageBox::Yes);
        return;
    }

    Group new_group("random", ui->input_gname->text(), current_user.getId());
    groups.push_back(new_group);
    current_groups.push_back(new_group);

    QMessageBox::information(this, tr("Success"), tr("创建成功"), QMessageBox::Yes);
    this->dashboard->reload();
    this->close();
}
